package edu.gxnu.cetcdemo.service.impl;

import edu.gxnu.cetcdemo.service.UploadService;
import edu.gxnu.cetcdemo.utils.Result;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.sql.Timestamp;

@Service
public class UploadServiceImpl implements UploadService {
    @Override
    public String uploadFile(String folderPath, MultipartFile file) throws IOException {
        File imageFolder = new File("E:/cetc-img" + folderPath);
        File f = new File(imageFolder,String.valueOf(System.currentTimeMillis()) + file.getOriginalFilename());
        System.out.println(f.getName());
        if (!f.getParentFile().exists())
            f.getParentFile().mkdirs();
        try {
            file.transferTo(f);
            String imgURL = "http://172.29.212.190:8080/api/file/"+ folderPath + f.getName();
            return imgURL;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

    @Override
    public Result uploadResult(String path) {
        return null;
    }

}
